package com.nbicc.anon.newpic.service.impl;

import com.nbicc.file.bo.FileDesc;
import com.nbicc.file.service.IFileService;
import com.nbicc.newpic.service.INewPicService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Service("AnonNewPicServiceImpl")
public class AnonNewPicServiceImpl implements INewPicService {

    @Resource(name = "FileServiceImpl")
    private IFileService fileService;

    @Override
    public void downloadFile(HttpServletRequest request, HttpServletResponse response, long id) throws IOException{
        FileDesc fileDesc = fileService.queryDownloadFileDesc(id, request);
        if(fileDesc != null){
            response.setHeader("Content-Disposition", "attachment;filename="+new String(fileDesc.getName().getBytes("utf-8"),"iso8859-1"));
            fileService.downloadFile(fileDesc , response.getOutputStream());
        }
    }

    @Override
    public FileDesc uploadFile(HttpServletRequest request, MultipartFile uploadFile) throws IOException {
        return null;
    }

    @Override
    public void deleteFile(Number id) throws IOException {

    }

}
